﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kunlun.Models;

namespace Kunlun.BusinessLogic {
	public class KunlunCollection {
		public static int InsertProduct(int uid, string pid) {
			KunLunEntities entities = new KunLunEntities();
			if (entities.Cats.Count(o => o.Pid == pid && o.Cid == uid) > 0) {
				return 0;
			}
			Cats c = new Cats();
			c.BeginDate = DateTime.Now;
			c.Pid = pid;
			c.Cid = uid;
			entities.Cats.Add(c);
			entities.SaveChanges();
			return c.ID;
		}

		public static List<Cats> GetProduct(int uid) {
			KunLunEntities entities = new KunLunEntities();

			return entities.Cats.Where(o => o.Cid == uid).ToList();
		}

		public static bool DeleteProduct(string pid) {
			KunLunEntities entities = new KunLunEntities();
			Cats c = entities.Cats.FirstOrDefault(o => o.Pid == pid);
			if (c != null) {
				
				entities.Cats.Remove(c);
				entities.SaveChanges();
				return true;
			}
			return false;

		}
	}
}
